package com.zdemo.factors;

import java.math.BigInteger;
import java.util.Arrays;

public class FactorCache {
	
	private final BigInteger lastNumber;
	private final BigInteger[] lastFactors;
	
	public FactorCache(BigInteger number, BigInteger[] factors) {
		lastNumber = number;
		lastFactors = Arrays.copyOf(factors, factors.length);
	}

	public BigInteger[] getFactors(BigInteger number) {
		if(lastNumber == null || ! lastNumber.equals(number)) {
			return null;
		} else {
            return Arrays.copyOf(lastFactors, lastFactors.length);
		}
		
	}
}
